package com.jiyun.yonghu.controller;

import cn.hutool.core.util.IdUtil;
import com.jiyun.vo.Result;
import com.jiyun.yonghu.domain.User;
import com.jiyun.yonghu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    UserService userService;

    @RequestMapping("list")
    public Result list(){
        return Result.seccuss(userService.list());
    }

    @RequestMapping("userlist")
    public List<User> userlist(){

        return  userService.list();
    }
    @RequestMapping("update")
    public Result update(@RequestBody User user){
        return Result.seccuss(userService.updateById(user));
    }
@RequestMapping("add")
    public Result add(@RequestBody User user){

    String id = IdUtil.getSnowflakeNextIdStr();
    user.setWorkNumber(id);
        return Result.seccuss(userService.save(user));
    }
}
